﻿using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace CPPEI.Coolzon.Designer.Views
{
    public static class PublishToServer
    {
        public static void Executed(object sender, ExecutedRoutedEventArgs e)
        {
            SolutionTreeViewNodeHelper.SaveCurrentScene();

            PublishToServerThread.Start(Designtime.Metadata.LocalStorage.GetSolutionDir(UIContext.Current.LocalWorkSpace.LocalPath, UIContext.Current.CurrentSolution.ID), UIContext.Current.CurrentSolution, Completed);
            ProgressbarWindow.Instance.ShowProgress(true);
        }
        public static void CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (UIContext.Current.CurrentSolution != null)
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }
        public static void Completed(bool result)
        {
            ProgressbarWindow.Instance.Complete();
            Application.Current.Dispatcher.Invoke(() =>
            {
                if (result)
                {
                    CustomMessageBox.ShowInfo("发布成功");
                }
                else
                {
                    CustomMessageBox.ShowError("发布失败");
                }
            });
        }
    }
}
